// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 

package com.xy.core.util;

import java.io.*;
import java.text.Collator;
import java.util.*;

public class FunctionsUtil
    implements Serializable
{

    public FunctionsUtil()
    {
    }

    public static String chopstr(String s, int i)
    {
        StringTokenizer stringtokenizer = new StringTokenizer(s, " ", true);
        int j = 0;
        boolean flag = true;
        String s1 = "";
        do
        {
            if(!stringtokenizer.hasMoreTokens())
                break;
            String s2 = stringtokenizer.nextToken();
            j += s2.length();
            if((j <= i) | flag)
            {
                s1 = (new StringBuilder()).append(s1).append(s2).toString();
            } else
            {
                s1 = (new StringBuilder()).append(s1).append(crlf).append(s2).toString();
                j = s2.length();
            }
            if(flag)
                flag = false;
        } while(true);
        return s1;
    }

    public static String firstToUpperCase(String s)
    {
        String s1 = s.substring(1, s.length());
        String s2 = (new StringBuilder()).append("").append(s.charAt(0)).toString().toUpperCase();
        return (new StringBuilder()).append(s2).append(s1).toString();
    }

    public static void copyAppend(String s, String s1)
        throws IOException
    {
        PrintWriter printwriter = new PrintWriter(new FileWriter(s1, true));
        BufferedReader bufferedreader = new BufferedReader(new FileReader(s));
        String s2;
        while((s2 = bufferedreader.readLine()) != null) 
            printwriter.println(s2);
        printwriter.close();
        bufferedreader.close();
    }

    public static String d2x(String s, int i, int j)
    {
        String s1 = "";
        String s2 = "";
        String s3 = "";
        String s4 = "";
        boolean flag = false;
        if(s.indexOf("-") >= 0)
            s2 = "D";
        else
            s2 = "C";
        int k = s.length();
        for(int l = 0; l < k; l++)
        {
            char c = s.charAt(l);
            if(c == '+' || c == '-')
                continue;
            if(c == '.')
            {
                flag = true;
                continue;
            }
            if(flag)
                s4 = (new StringBuilder()).append(s4).append(c).toString();
            else
                s3 = (new StringBuilder()).append(s3).append(c).toString();
        }

        int i1 = i - j;
        if(s3.length() < i1)
            s3 = Pad(s3, '0', -1 * i1);
        if(i % 2 == 0)
            s3 = (new StringBuilder()).append("0").append(s3).toString();
        if(s4.length() < j)
            s4 = Pad(s4, '0', j);
        s1 = s2x((new StringBuilder()).append(s3).append(s4).append(s2).toString());
        return s1;
    }

    public static int exp(int i, int j)
    {
        int k = i;
        if(j > 0)
        {
            for(int l = 1; l < j; l++)
                k *= i;

        } else
        {
            k = 1;
        }
        return k;
    }

    public static String getArg(String as[], int i)
    {
        return i < 0 || i >= as.length ? "" : as[i].toUpperCase();
    }

    public static String getArg(String as[], int i, boolean flag)
    {
        String s = "";
        s = getArg(as, i);
        if(flag && i >= 0)
        {
            for(int j = i + 1; j < as.length; j++)
                s = (new StringBuilder()).append(s).append(" ").append(as[j]).toString();

        }
        return s.toUpperCase();
    }

    public static String getFmtString(String s, String s1)
    {
        int i = 0;
        int j = 0;
        StringTokenizer stringtokenizer = new StringTokenizer(s1, " (),");
        String s2 = "";
        boolean flag = true;
        while(stringtokenizer.hasMoreTokens()) 
        {
            String s3 = stringtokenizer.nextToken().trim();
            try
            {
                Integer integer = new Integer(s3);
                if(flag)
                {
                    i = integer.intValue();
                    flag = false;
                } else
                {
                    j = integer.intValue();
                }
            }
            catch(Exception exception) { }
        }
        return getFmtString(s, i, j);
    }

    public static String getFmtString(String s, int i, int j)
    {
        int k = i - j;
        StringBuffer stringbuffer = new StringBuffer("");
        int l = 0;
        for(int i1 = 0; i1 < k; i1++)
        {
            if(l == 3)
            {
                stringbuffer.insert(0, ",");
                l = 0;
            }
            if(i1 == 0)
                stringbuffer.insert(0, "0");
            else
                stringbuffer.insert(0, "#");
            l++;
        }

        for(int j1 = 0; j1 < j; j1++)
            if(j1 == 0)
                stringbuffer.append(".0");
            else
                stringbuffer.append("0");

        return (new StringBuilder()).append("   private static String ").append(s).append("Fmt ").append(" = ").append(quote).append(stringbuffer.toString()).append(quote).append(";").toString();
    }

    public static String getFmtString(String s, String s1, String s2)
    {
        int i = (new Integer(s1)).intValue();
        int j = (new Integer(s2)).intValue();
        return getFmtString(s, i, j);
    }

    public static String getOpt(String s, String s1)
    {
        String s2 = "";
        int i = s.indexOf(s1);
        if(i >= 0)
        {
            int j = s.length();
            int k = i + s1.length();
            int l = s.indexOf(' ', k);
            if(l >= 0 && l < j)
                j = l;
            l = s.indexOf('/', k);
            if(l >= 0 && l < j)
                j = l;
            s2 = s.substring(k, j);
        }
        return s2;
    }

    public static String getParameter(String s, String s1, String s2)
    {
        String s3 = "";
        if(s1 == null || s == null)
            return s3;
        StringTokenizer stringtokenizer = new StringTokenizer(s, s2);
        do
        {
            if(!stringtokenizer.hasMoreTokens())
                break;
            String s4 = stringtokenizer.nextToken().trim();
            if(!s4.equals(s1))
                continue;
            if(stringtokenizer.hasMoreTokens())
                s3 = stringtokenizer.nextToken().trim();
            break;
        } while(true);
        return s3;
    }

    public static String getScale(String s)
    {
        StringBuffer stringbuffer = new StringBuffer("");
        boolean flag = false;
        int j = 0;
        StringTokenizer stringtokenizer = new StringTokenizer(s, " (),");
        String s1 = "";
        boolean flag1 = true;
        while(stringtokenizer.hasMoreTokens()) 
        {
            String s2 = stringtokenizer.nextToken().trim();
            try
            {
                Integer integer = new Integer(s2);
                if(flag1)
                {
                    int i = integer.intValue();
                    flag1 = false;
                } else
                {
                    j = integer.intValue();
                }
            }
            catch(Exception exception) { }
        }
        Integer integer1 = new Integer(j);
        return integer1.toString();
    }

    public static void globalChange(String s, String s1, String s2, boolean flag)
        throws Exception
    {
        File file = new File(s);
        if(file.isFile())
            searchReplace(s, s1, s2, "");
        else
        if(file.isDirectory())
        {
            String as[] = file.list();
            for(int i = 0; i < as.length; i++)
            {
                File file1 = new File(file, as[i]);
                if(file1.isFile() || flag)
                    globalChange(file1.getAbsolutePath(), s1, s2, flag);
            }

        } else
        {
            throw new Exception((new StringBuilder()).append("Error in reading ").append(s).toString());
        }
    }

    public static int hexval(char c)
    {
        int i = c;
        if(i < ':')
            i = c & 0xf;
        else
            i = (c & 0xf) + 9;
        return i;
    }

    public static String i2x(String s, int i)
    {
        Integer integer = new Integer(s);
        int j = integer.intValue();
        String s1 = Integer.toHexString(j);
        s1 = s1.toUpperCase();
        int k = s1.length();
        int l = i * 2;
        if(k < l)
            s1 = Pad(s1, '0', -1 * l);
        else
        if(k > l)
            s1 = s1.substring(k - l);
        String s2 = s2x(s1);
        return s2;
    }

    public static void searchReplace(String s, String s1, String s2, String s3)
    {
        boolean flag;
        boolean flag1;
        String s4 = s3.toUpperCase();
        flag = s4.indexOf("/D") >= 0;
        flag1 = s4.indexOf("/A") >= 0;
        File file;
        String s6;
        File file1;
        file = new File(s);
        String s5 = s;
        if(s5.indexOf(".") > 0)
        {
            StringTokenizer stringtokenizer = new StringTokenizer(s5, ".");
            s5 = stringtokenizer.nextToken().trim();
        }
        s6 = (new StringBuilder()).append(s5).append(".BAK").toString();
        file1 = new File(s6);
        if(s.equals(s6))
            return;
        try
        {
            if(file1.exists())
                file1.delete();
            file.renameTo(file1);
            PrintWriter printwriter = new PrintWriter(new FileWriter(s));
            BufferedReader bufferedreader = new BufferedReader(new FileReader(s6));
            String s7 = bufferedreader.readLine();
            int i = 0;
            for(; s7 != null; s7 = bufferedreader.readLine())
            {
                int j = s7.indexOf(s1);
                if(j >= 0)
                {
                    i++;
                    if(flag)
                        s7 = s2;
                    else
                        s7 = replaceString(s7, s1, s2);
                }
                printwriter.println(s7);
            }

            if(flag1 && i == 0 && !s2.equals(""))
                printwriter.println(s2);
            bufferedreader.close();
            printwriter.close();
        }
        catch(Exception exception)
        {
            System.out.println((new StringBuilder()).append("Error in jsrchrepl  --> ").append(crlf).append(exception.toString()).toString());
            exception.printStackTrace();
            System.exit(12);
        }
        return;
    }

    public static void logMsg(String s, String s1)
        throws IOException
    {
        PrintWriter printwriter = new PrintWriter(new FileWriter(s1, true));
        printwriter.println(s);
        printwriter.close();
    }

    public static String makeBusName(String s)
    {
        StringBuffer stringbuffer = new StringBuffer("");
        String s1 = " _/.,#'%-";
        String s2 = "0123456789";
        int i = s.length();
        char ac[] = new char[1];
        boolean flag = true;
        for(int j = 0; j < i; j++)
        {
            ac[0] = s.charAt(j);
            String s3 = new String(ac);
            if(s1.indexOf(s3) >= 0)
            {
                if(s3.equals("'"))
                    flag = false;
                else
                    flag = true;
                stringbuffer.append(s3);
                continue;
            }
            if(flag)
            {
                stringbuffer.append(s3.toUpperCase());
                flag = false;
            } else
            {
                stringbuffer.append(s3.toLowerCase());
            }
        }

        if(s2.indexOf(String.valueOf(stringbuffer.charAt(0))) >= 0)
            stringbuffer = stringbuffer.insert(0, 'X');
        return stringbuffer.toString();
    }

    public static String makeClassName(String s)
    {
        return makeFirstLetterUpperCase(makeVarName(s));
    }

    public static String makeFirstLetterLowerCase(String s)
    {
        if(s.length() == 0)
        {
            return s;
        } else
        {
            char ac[] = new char[1];
            ac[0] = s.charAt(0);
            String s1 = new String(ac);
            return (new StringBuilder()).append(s1.toLowerCase()).append(s.substring(1)).toString();
        }
    }

    public static String makeFirstLetterUpperCase(String s)
    {
        if(s.length() == 0)
        {
            return s;
        } else
        {
            char ac[] = new char[1];
            ac[0] = s.charAt(0);
            String s1 = new String(ac);
            return (new StringBuilder()).append(s1.toUpperCase()).append(s.substring(1)).toString();
        }
    }

    public static String makeVarName(String s)
    {
        boolean flag = true;
        StringBuffer stringbuffer = new StringBuffer("");
        String s1 = " _/.,#'%-";
        String s2 = "0123456789";
        int i = s.length();
        char ac[] = new char[1];
        boolean flag1 = false;
        boolean flag2 = true;
        for(int j = 0; j < i; j++)
        {
            ac[0] = s.charAt(j);
            String s3 = new String(ac);
            if(!flag)
                s3 = s3.toLowerCase();
            if(s1.indexOf(s3) >= 0)
            {
                if(s3.equals("'"))
                    flag1 = false;
                else
                    flag1 = true;
                continue;
            }
            if(flag1)
            {
                if(!flag2)
                    stringbuffer.append(s3.toUpperCase());
                else
                    stringbuffer.append(s3);
                flag2 = false;
                flag1 = false;
            } else
            {
                stringbuffer.append(s3);
                flag2 = false;
            }
        }

        if(s2.indexOf(String.valueOf(stringbuffer.charAt(0))) >= 0)
            stringbuffer = stringbuffer.insert(0, 'x');
        return stringbuffer.toString();
    }

    public static String ovly(String s, String s1, int i, int j)
    {
        int k = s1.length();
        int l = j;
        int i1 = s.length();
        int j1 = 0;
        String s2 = s;
        if(l == 0)
            l = s1.length();
        if(l == -1)
            l = -1 * s1.length();
        if(l >= 0)
            j1 = (l + i) - 1;
        if(j1 > i1)
            i1 = j1;
        char ac[] = new char[i1];
        ac = s.toCharArray();
        for(int k1 = 0; k1 < k; k1++)
        {
            if(l > 0)
            {
                int l1 = (i + k1) - 1;
                if((l1 >= 0) & (l1 < i1))
                    ac[l1] = s1.charAt(k1);
            } else
            if(l < 0)
            {
                int i2 = k - k1 - 1;
                int j2 = i - 1 - k1;
                if((j2 >= 0) & (j2 < i1))
                    ac[j2] = s1.charAt(i2);
            }
            s2 = new String(ac);
        }

        return s2;
    }

    public static String Pad(String s, char c, int i)
    {
        int j = i;
        if(j < 0)
            j = -1 * j;
        int k = j - s.length();
        String s1 = s;
        if(k > 0)
        {
            for(int l = 0; l < k; l++)
                if(i >= 0)
                    s1 = (new StringBuilder()).append(s1).append(c).toString();
                else
                    s1 = (new StringBuilder()).append(c).append(s1).toString();

        } else
        {
            s1 = s.substring(0, j);
        }
        return s1;
    }

    public static String PadHex40(String s, int i)
    {
        int j = s.length();
        int k = i - j;
        int l = hex40.length;
        if(k <= l && k > 0)
        {
            return (new StringBuilder()).append(s).append(new String(hex40, 0, k)).toString();
        } else
        {
            char c = '@';
            return Pad(s, c, i);
        }
    }

    public static String Padn(String s, char c, int i)
    {
        int j = i;
        if(i < 0)
            j = i * -1;
        if(s.length() > j)
            return s;
        else
            return Pad(s, c, i);
    }

    public static final Hashtable parseStringToHashtable(String s, String s1)
    {
        Hashtable hashtable = new Hashtable();
        if(s == null)
            return hashtable;
        StringTokenizer stringtokenizer = new StringTokenizer(s, s1);
        do
        {
            if(!stringtokenizer.hasMoreTokens())
                break;
            String s2 = stringtokenizer.nextToken().trim();
            if(!s2.equals(""))
                hashtable.put(s2, "");
        } while(true);
        return hashtable;
    }

    public static boolean patternMatch(String s, String s1)
    {
        if(s1.equals("*"))
            return true;
        if(s1.startsWith("*"))
        {
            String s2 = s1.substring(1);
            for(int j = 0; j < s.length(); j++)
                if(patternMatch(s.substring(j), s2))
                    return true;

            return false;
        }
        int i = s1.indexOf("*");
        if(i < 0)
        {
            return s.equals(s1);
        } else
        {
            String s3 = s1.substring(0, i);
            return s.startsWith(s3) && patternMatch(s.substring(i), s1.substring(i));
        }
    }

    public static String replaceString(String s, String s1, String s2)
    {
        int i = s.indexOf(s1);
        if(i < 0 || s1.length() == 0)
            return s;
        else
            return (new StringBuilder()).append(s.substring(0, i)).append(s2).append(replaceString(s.substring(i + s1.length()), s1, s2)).toString();
    }

    public static String s2x(String s)
    {
        String s1 = "";
        int i = s.length();
        for(int l = 0; l < i; l++)
        {
            int k = hexval(s.charAt(l)) * 16;
            int j;
            if(++l >= i)
                j = 0;
            else
                j = hexval(s.charAt(l));
            s1 = (new StringBuilder()).append(s1).append((char)(k + j)).toString();
        }

        return s1;
    }

    public static String getCurrentDate()
    {
        Date date = new Date();
        return date.toString();
    }

    public static void sortStringArray(String as[])
    {
        Collator collator = Collator.getInstance();
        collator.setStrength(0);
        int i = as.length;
        for(int j = i; j > 1; j--)
        {
            for(int k = 0; k < j - 1; k++)
                if(collator.compare(as[k], as[k + 1]) > 0)
                {
                    String s = as[k];
                    as[k] = as[k + 1];
                    as[k + 1] = s;
                }

        }

    }

    public static String stripspecial(String s)
    {
        StringBuffer stringbuffer = new StringBuffer("");
        String s1 = " _/.,#'-%";
        int i = s.length();
        char ac[] = new char[1];
        for(int j = 0; j < i; j++)
        {
            ac[0] = s.charAt(j);
            String s2 = new String(ac);
            if(s1.indexOf(s2) < 0)
                stringbuffer.append(s2);
        }

        return stringbuffer.toString();
    }

    public static String stripzero(String s)
    {
        String s1 = "";
        boolean flag = true;
        int i = s.length();
        for(int j = 0; j < i; j++)
        {
            char c = s.charAt(j);
            if(!flag || c != '0')
            {
                s1 = (new StringBuilder()).append(s1).append(c).toString();
                flag = false;
            }
        }

        if(s1.equals(""))
            s1 = "0";
        return s1;
    }

    public static String x2d(ByteArrayInputStream bytearrayinputstream, int i, int j)
    {
        String s = "";
        String s1 = "";
        String s2 = "";
        int k = i % 2;
        if(k == 1)
            k = 0;
        else
            k = 1;
        int l = -1 * (i + j);
        int i1 = i - j;
        String s3 = x2s(bytearrayinputstream);
        int j1 = s3.length();
        s2 = s3.substring(j1 - 1);
        if(s2.equals("D"))
            s1 = "-";
        s3 = s3.substring(0, j1 - 1);
        if(i1 > 0)
            s = s3.substring(0, i1 + k);
        if(j > 0)
            s = (new StringBuilder()).append(s).append(".").append(s3.substring(i1 + k)).toString();
        s = (new StringBuilder()).append(s1).append(stripzero(s)).toString();
        return s;
    }

    public static String x2d(String s, int i, int j)
    {
        String s1 = "";
        String s2 = "";
        String s3 = "";
        int k = i % 2;
        if(k == 1)
            k = 0;
        else
            k = 1;
        int l = -1 * (i + j);
        int i1 = i - j;
        String s4 = x2s(s);
        int j1 = s4.length();
        s3 = s4.substring(j1 - 1);
        if(s3.equals("D"))
            s2 = "-";
        s4 = s4.substring(0, j1 - 1);
        if(i1 > 0)
            s1 = s4.substring(0, i1 + k);
        if(j > 0)
            s1 = (new StringBuilder()).append(s1).append(".").append(s4.substring(i1 + k)).toString();
        s1 = (new StringBuilder()).append(s2).append(stripzero(s1)).toString();
        return s1;
    }

    public static String x2i(ByteArrayInputStream bytearrayinputstream, boolean flag)
    {
        String s = "";
        try
        {
            String s1 = x2s(bytearrayinputstream);
            int i = s1.length();
            boolean flag1 = false;
            long l = 0L;
            for(int k = 0; k < i; k++)
            {
                int i1 = i - k - 1;
                int j1 = hexval(s1.charAt(i1));
                int j = j1 * exp(16, k);
                l += j;
            }

            if(flag)
            {
                if(l > 32767L)
                    l -= 0x10000L;
            } else
            if(l > 0x7fffffffL)
                l -= 0x100000000L;
            Long long1 = new Long(l);
            s = long1.toString();
        }
        catch(Exception exception)
        {
            return (new StringBuilder()).append("Error: ").append(exception).toString();
        }
        return s;
    }

    public static String x2i(String s, boolean flag)
    {
        String s1 = "";
        try
        {
            String s2 = x2s(s);
            int i = s2.length();
            boolean flag1 = false;
            long l = 0L;
            for(int k = 0; k < i; k++)
            {
                int i1 = i - k - 1;
                int j1 = hexval(s2.charAt(i1));
                int j = j1 * exp(16, k);
                l += j;
            }

            if(flag)
            {
                if(l > 32767L)
                    l -= 0x10000L;
            } else
            if(l > 0x7fffffffL)
                l -= 0x100000000L;
            Long long1 = new Long(l);
            s1 = long1.toString();
        }
        catch(Exception exception)
        {
            return (new StringBuilder()).append("Error: ").append(exception).toString();
        }
        return s1;
    }

    public static String x2s(ByteArrayInputStream bytearrayinputstream)
    {
        String s = "";
        int i = bytearrayinputstream.available();
        int j = i * 2;
        String s1 = "";
        for(int k = 0; k < i; k++)
        {
            int l = bytearrayinputstream.read();
            String s2 = Integer.toHexString(l);
            if(s2.length() == 1)
                s = (new StringBuilder()).append(s).append("0").append(s2).toString();
            else
                s = (new StringBuilder()).append(s).append(s2).toString();
        }

        return s.toUpperCase();
    }

    public static Properties extractProperties(Properties properties, String s)
    {
        Properties properties1 = new Properties();
        Enumeration enumeration = properties.keys();
        do
        {
            if(!enumeration.hasMoreElements())
                break;
            String s1 = (String)enumeration.nextElement();
            if(s1 != null && s1.indexOf(s) >= 0)
            {
                String s2 = properties.getProperty(s1);
                properties1.put(s1, s2);
            }
        } while(true);
        return properties1;
    }

    public static List extractPropertyValues(Properties properties)
    {
        ArrayList arraylist = new ArrayList();
        for(Enumeration enumeration = properties.elements(); enumeration.hasMoreElements(); arraylist.add(enumeration.nextElement()));
        return arraylist;
    }

    public static void createDir(File file)
    {
        if(file.exists())
            return;
        File file1 = new File(file.getParent());
        if(!file1.isDirectory())
            file1.mkdirs();
    }

    public static boolean hasMask(String s, String s1)
    {
        boolean flag = s.toUpperCase().indexOf(s1.toUpperCase()) >= 0;
        return flag;
    }

    public static String makeLowerCase(String s)
    {
        return s.toLowerCase();
    }

    public static String makeUpperCase(String s)
    {
        return s.toUpperCase();
    }

    public static String x2s(String s)
    {
        String s1 = "";
        int i = s.length();
        int j = i * 2;
        String s2 = "";
        for(int k = 0; k < i; k++)
        {
            char c = s.charAt(k);
            String s3 = Integer.toHexString(c);
            if(s3.length() == 1)
                s1 = (new StringBuilder()).append(s1).append("0").append(s3).toString();
            else
                s1 = (new StringBuilder()).append(s1).append(s3).toString();
        }

        return s1.toUpperCase();
    }

    public static String quote(String s)
    {
        return (new StringBuilder()).append(quote).append(s).append(quote).toString();
    }

    public static char crchar[] = {
        '\r', '\n'
    };
    public static String crlf;
    public static char cr = '\r';
    public static char lf = '\n';
    public static char quchar[] = {
        '"'
    };
    public static char quBlank[] = {
        '"', '"'
    };
    public static String quote;
    public static String blankQuote;
    public static String fs;
    private static char hex40[];

    static 
    {
        crlf = new String(crchar);
        quote = new String(quchar);
        blankQuote = new String(quBlank);
        fs = File.separator;
        hex40 = null;
        hex40 = new char[4000];
        for(int i = 0; i < 4000; i++)
            hex40[i] = '@';

    }
}
